package com.kaka.controller;

import com.kaka.dao.UserDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
@WebServlet(name = "DeleteUserServlet", urlPatterns = "/DeleteUserServlet")
public class DeleteUserServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("================================");
        request.setCharacterEncoding("UTF-8"); // 中文处理
        try {
            //接收页面提交的参数
            String username = request.getParameter("username");
            System.out.println(username + "================================");
            int id = Integer.parseInt(request.getParameter("id"));

            //将接收的3个参数传递到 UserDao 中将数据保存
            UserDao dao = new UserDao();
            dao.delete(username,id);
            // 转发到列表页面
            request.getRequestDispatcher("/UserServlet").forward(request,response);

        } catch (Exception e){
            e.printStackTrace();
        }


    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}